package com.frombottom2top.hexdefence.utils;

import com.frombottom2top.hexdefence.game.Game;

import java.util.*;
/**
 * Created by Administrator on 2016/6/2.
 */
public class AStarComparator implements Comparator<int[][]> {
    Game game;  //Game类引用
    public AStarComparator(Game game){ //构造器
        this.game = game;
    }
    public int compare(int[][] o1,int[][] o2){
        int[] t1 = o1[1]; //col
        int[] t2 = o2[1]; //row
        int[] target = game.target; //直线物理距离
        int a = game.getVisited(o1[0][1],o1[0][0]) + Math.abs(t1[0]-target[0]) + Math.abs(t1[1]-target[1]);
        int b = game.getVisited(o2[0][1],o2[0][0]) + Math.abs(t2[0]-target[0]) + Math.abs(t2[1]-target[1]);
        if (game.map_tower[o1[0][1]][o1[0][0]] >= 6 && game.map_tower[o1[0][1]][o1[0][0]] <= 11){
            a += 2;
        }
        if (game.map_tower[o2[0][1]][o2[0][0]] >= 6 && game.map_tower[o2[0][1]][o2[0][0]] <= 11){
            b += 2;
        }
        return a-b;//返回距离值
    }
//    public boolean equals(Objects obj){
//        return false;
//    }
}
